home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / bindings / OSamiga.awk < prev    next >
Encoding:
AWK Script  |  1996-09-27  |  3.3 KB  |  126 lines

  1. #{{{}}}
  2. #{{{  comments/syntax description
  3. # Format for the sources
  4. # ( AMIGA
  5. #        start amiga stuff
  6. #    ( AREXX name f )
  7. #        AREXX function name calls OCL function f
  8. #    TERMINAL ....
  9. #        ... will used as terminal description in the bindings
  10. #    ( MODES name .. )
  11. #        all names are known as mode
  12. #    ( IFMODES tag name ... )
  13. #        all names are known as mode, if OCL-Tag tag is set
  14. #    ( MENU header of the menu
  15. #      item : command
  16. #      item : ( command mode ) ..
  17. #    )
  18. #        define a menu with all items. The first version of item has to be used,
  19. #        if no modes are defined.
  20. # )
  21. #        end AMIGA stuff
  22. #}}}
  23. #{{{  init, not in statements
  24. BEGIN { modes_used=0;menu="";DQ=sprintf("%c",34);menu_top=0;first_code=48;terminal="default" }
  25. #}}}
  26. #{{{  skip comments
  27. /^ *;/ { next }
  28. #}}}
  29. #{{{  (AMIGA: switch on amiga handling
  30. /^ *\( +AMIGA *$/ { amiga_handle=1;next }
  31. #}}}
  32. #{{{  skip non AMIGA parts
  33. amiga_handle!=1   { next }
  34. #}}}
  35. #{{{  ): switch off AMIGA
  36. /^ *\) *$/ && menu=="" { amiga_handle=0;next }
  37. #}}}
  38. #{{{  AREX
  39. /^ *\( +AREXX +[^     ()]+ +[^     ()]+ +\) *$/ && menu=="" {
  40.    txt=""
  41.    for (i=1;i<=length($3);i++)
  42.       txt=txt" "DQ substr($3,i,1)" "
  43.    print("( os-extension ( "DQ"AREXX "txt" "DQ", "$4" ) )")
  44.    next
  45. }
  46. #}}}
  47. #{{{  TERMINAL: specify terminal string for bindings
  48. /^ *TERMINAL.*/ {
  49.    for (terminal=$0;substr(terminal,1,1)==" ";terminal=substr(terminal,2));
  50.    terminal=substr(terminal,9)
  51.    next
  52. }
  53. #}}}
  54. #{{{  (MODES ): define modes for menu-keybinds
  55. / *\( +MODES( +[^ "    ()]+)+ +\) *$/ {
  56.    modes_used=1
  57.    for ( i=3 ; i < NF ; i++ )
  58.       modes[$i]=1
  59.    next
  60. }
  61. #}}}
  62. #{{{  (IFMODES ): define modes for menu-keybinds, depending on ifdefs
  63. / *\( +IFMODES +[^     ()]+( +[^ "    ()]+)+ +\) *$/ {
  64.    modes_used=1
  65.    for ( i=4 ; i < NF ; i++ ) {
  66.       modes[$i]=1
  67.       ifuse[$i]=$3
  68.    }
  69.    next
  70. }
  71. #}}}
  72. #{{{  (MENU: start menu definition
  73. /^ *\( +MENU( +[^     ()]+)+ *$/ {
  74.    menu=$3
  75.    for (i=4;i<=NF;i++)
  76.       menu=menu" "$i
  77.    menues[menu]=1
  78.    txt="( os-extension ( "DQ"MENU "DQ" "
  79.    for (i=1;i<=length(menu);i++)
  80.       txt=txt" "DQ substr(menu,i,1)
  81.    txt=txt" "DQ","
  82.    menu_sub=0
  83.    next
  84. }
  85. #}}}
  86. #{{{  ) and menu_handling: end menu handling
  87. /^ *\) *$/ && menu!="" { menu="";menu_top++;next }
  88. #}}}
  89. #{{{  menu command line
  90. /^.+:(( +[^     ()]+)|( +\( +[^     ()]+ +[^     ()]+ +\))+) *$/ {
  91.    line=txt
  92.    for (sf=1;$sf!=":";sf++) {
  93.       for (j=1;j<=length($sf);j++)
  94.          line=line" "DQ substr($sf,j,1)
  95.       line=line" "DQ" "
  96.    }
  97.    print(line" ) )")
  98.    if (NF==sf+1 && modes_used==0) {
  99.       printf("( terminal ( %s )\n ( keybind %s ( $menu "DQ"%c "DQ"%c ) )\n)\n",terminal,$3,menu_top+first_code,menu_sub+first_code)
  100.       menu_sub++
  101.       next
  102.    } else if (NF>sf+1 && modes_used==1) {
  103.       for (i=sf+2;sf<NF;sf+=4) {
  104.          if (modes[$(i+1)]!=1) {
  105.             print("@error unknown mode "$(i+1))
  106.             next
  107.          }
  108.          if (ifuse[$(i+1)]!="")
  109.             print("@if-using ("ifuse[$(i+1)]")")
  110.          printf("( mode %s\n ( terminal ( %s )\n  ( keybind %s ( $menu "DQ"%c "DQ"%c ) )\n )\n)\n",$(i+1),terminal,$i,menu_top+first_code,menu_sub+first_code)
  111.          if (ifuse[$(i+1)]!="")
  112.             print("@fi")
  113.       }
  114.       menu_sub++
  115.       next
  116.    }
  117. }
  118. #}}}
  119. { print("@error invalid amiga extension >"$0"<")
  120.   exit
  121. }
  122. END {
  123.    if (amiga_handle==1)
  124.       print("@error missing end of amiga extensions!")
  125. }
  126.